//
//  KINGUIButton+Extension.swift
//  肉荣微博
//
//  Created by king on 15/8/2.
//  Copyright © 2015年 king. All rights reserved.
//

import UIKit

extension UIButton {

    convenience init(title: String, imageName:String, normalBackgroudImageName: String = "timeline_card_bottom_background", highlightedBackgroudImageName: String = "timeline_card_middle_background_highlighted", fontSize:CGFloat = 12.0, color:UIColor = UIColor.darkGrayColor()) {
        self.init()
        setTitle(title, forState: UIControlState.Normal)
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: normalBackgroudImageName), forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: highlightedBackgroudImageName), forState: UIControlState.Highlighted)
        setTitleColor(color, forState: UIControlState.Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
    }
    
    convenience init(title: String, fontSize:CGFloat, color:UIColor, backColor:UIColor) {
        self.init()
        setTitle(title, forState: UIControlState.Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        titleLabel?.textColor = color
        backgroundColor = backColor
    }
    
    convenience init(imageName:String) {
        self.init()
        setImage(imageName)
    }
    
    func setImage(imageName:String) {
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
    }

}
